import { _decorator, Component, Node, Animation, director, DirectionalLight, SpotLight, SphereLight, Label, Game  } from 'cc';
import Util from './Util';
import { GameManager } from "./GameManager";
import { SkinManager } from "./SkinManager";

const { ccclass, property } = _decorator;

@ccclass('UIController') // 用 @ccclass 声明类为 Cocos 组件
export class UIController extends Component {

    @property(Node) siteLayer!: Node;
    @property(Node) testLayer!: Node;
    // 通过 @property 让编辑器可以配置属性
    @property(Node) action: Node | null = null;
    @property(Node) startAni: Node | null = null;

    @property(Label) label: Label | null = null;

    start() {
        // 脚本启动时的逻辑
        console.log('Component started!');
    }

    
    // update(deltaTime: number) {
    //     // 每帧调用的逻辑
    //     // console.log('Updating...');
    // }

    onSettingClick() {
        console.log("onButtonClick...");

        Util.return2DGame();
    }

    onSwitchDeskSkin() {
        let index = SkinManager.instance.getDesktopSkin();
        index++;
        if(index >= 4)
            index = 0;
        SkinManager.instance.setDesktopSkin(index);
    }

    onSwitchCardSkin() {
        let index = SkinManager.instance.getCardSkin();
        index++;
        if(index >= 4)
            index = 0;
        SkinManager.instance.setCardSkin(index);
    }

    onPeng() {

        this.action?.getComponent(Animation)?.play("CardAction"); 
        GameManager.instance.onCardAction();

    }

    onShowClick() {
        GameManager.instance.gameStart();
    }

    onTest1Click() {
        GameManager.getPlayer().getSelf()?.getHandCard().drawCard();
        
        for(let i = 0; i < 4; i++)
        {
            GameManager.getOut().onOutCard(i);
        }
    }

    onTest2Click() {
        GameManager.instance.onGameEnd()
    }

    onTest3Click() {
        GameManager.instance.onStartCard();
    }


    onHeadClick() {

    }

    onTakeSeat(event: Event, customEventData: string): void {
        console.log("onCardClick...", customEventData);
        const index = parseInt(customEventData);
        GameManager.getDirector().changeViewPort(index);

        GameManager.getPlayer().setMySite(index);

        this.siteLayer.active = false;
        this.testLayer.active = true;
    }
}